# TODO: Add ThreadPoolXNNPACK.cc when XNNPACK integration is updated
# to pass the actual threadpool ptr instead of nullptr.
if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)
  add_definitions(-DUSE_INTERNAL_THREADPOOL_IMPL)
  list(APPEND Caffe2_CPU_SRCS
    utils/string_utils.cc
    utils/threadpool/pthreadpool.cc
    utils/threadpool/pthreadpool_impl.cc
    utils/threadpool/pthreadpool_new_if_impl.c
    utils/threadpool/ThreadPool.cc
    utils/threadpool/ThreadPoolMobile.cc
    utils/threadpool/ThreadPoolXNNPACK.cc
  )
  set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
  return()
endif()

list(APPEND Caffe2_CPU_SRCS
  utils/bench_utils.cc
  utils/cpuid.cc
  utils/math/broadcast.cc
  utils/math/elementwise.cc
  utils/math/reduce.cc
  utils/math/transpose.cc
  utils/math/utils.cc
  utils/math_cpu.cc
  utils/murmur_hash3.cc
  utils/proto_convert.cc
  utils/proto_utils.cc
  utils/proto_wrap.cc
  utils/signal_handler.cc
  utils/smart_tensor_printer.cc
  utils/string_utils.cc
  utils/threadpool/ThreadPool.cc)

# ---[ threadpool/pthreadpool* is a local modification of the NNPACK
# pthreadpool with a very similar interface. Neither NNPACK, nor this
# thread pool supports Windows.
if(NOT MSVC)
  add_definitions(-DUSE_INTERNAL_THREADPOOL_IMPL)
  set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS}
          utils/threadpool/pthreadpool.cc
          utils/threadpool/pthreadpool_impl.cc
          utils/threadpool/pthreadpool_new_if_impl.c
          utils/threadpool/ThreadPoolMobile.cc
          utils/threadpool/ThreadPoolXNNPACK.cc
          )
endif()

set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS}
        utils/math/broadcast.cu
        utils/math/elementwise.cu
        utils/math/reduce.cu
        utils/math/transpose.cu
        utils/math_gpu.cu
        )

set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS}
        utils/math/hip/broadcast.hip
        utils/math/hip/elementwise.hip
        utils/math/hip/reduce.hip
        utils/math/hip/transpose.hip
        utils/hip/math_gpu.hip
        )

set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS}
        utils/fixed_divisor_test.cc
        utils/math_test.cc
        utils/fatal_signal_asan_no_sig_test.cc
        utils/simple_queue_test.cc
        utils/proto_utils_test.cc
        utils/cpuid_test.cc
        utils/smart_tensor_printer_test.cc
        utils/cast_test.cc
        )

set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS}
        utils/math_gpu_test.cc
        )

set(Caffe2_HIP_TEST_SRCS ${Caffe2_HIP_TEST_SRCS}
        utils/hip/math_gpu_test.cc
        utils/hip/math_blas_gpu_test.cc
        )

# TODO Once all source files are defined inside the local c10_utils_xxx targets,
# it should be the job of the parent CMakeLists.txt to decide what to do with the target (i.e. link it to caffe2)
# instead of us locally adding it to Caffe2_xxx variables.
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)
set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} PARENT_SCOPE)
set(Caffe2_HIP_SRCS ${Caffe2_HIP_SRCS} PARENT_SCOPE)
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)
set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS} PARENT_SCOPE)
set(Caffe2_HIP_TEST_SRCS ${Caffe2_HIP_TEST_SRCS} PARENT_SCOPE)
